package com.abel.web.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.abel.web.view.DesiredPositionsViewBean;

public class DesiredPositionsValidator implements Validator {

	@SuppressWarnings("rawtypes")
	@Override
	public boolean supports(Class clazz) {
		
		return DesiredPositionsViewBean.class.equals(clazz);
	}

	@Override
	public void validate(Object obj, Errors errors) {
		
		DesiredPositionsViewBean viewBean = (DesiredPositionsViewBean)obj;
		
//		if (viewBean.getLeastSalaryAccepted() != null 
//				&& !viewBean.getLeastSalaryAccepted().equals("")
//				&& !viewBean.getLeastSalaryAccepted().matches("[0-9]*")) {
//			
//			errors.rejectValue("leastSalaryAccepted", "error.null",null,"Least salary accepted should be a valid numeric value");
//		}
//
//		if (viewBean.getSalaryDesired() != null 
//				&& !viewBean.getSalaryDesired().equals("")
//				&& !viewBean.getSalaryDesired().matches("[0-9]*")) {
//			
//			errors.rejectValue("salaryDesired", "error.null",null,"Salary desired should be a valid numeric value");
//		}
		
		if (viewBean.getLeastSalaryAccepted() < 0) {
			errors.rejectValue("leastSalaryAccepted", "error.null",null,"Least salary accepted should be a valid numeric value");
		}
		
		if (viewBean.getSalaryDesired() < 0) {
			errors.rejectValue("salaryDesired", "error.null",null,"Salary desired should be a valid numeric value");
		}
	}
}
